package com.me.study.javaBasic.dataType;

import org.junit.Assert;
import org.junit.Test;

import java.text.ChoiceFormat;
import java.text.NumberFormat;

/**
 * ChoiceFormat 测试：相当于以数字为键，字符串为值的键值对   <p>
 *  见  https://mp.weixin.qq.com/s/ENKwVqPE1cuOgE51ODJnnw
 *
 * @author ME
 * @date 2021/4/26
 */
public class TestChoiceFormat {

    /**
     * double 去尾再匹配，超过候选项的最大值则取最大的
     */
    @Test
    public void test1() {
        double[] limits = {1, 2, 3, 4, 5, 6, 7};
        String[] formats = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
        NumberFormat numberFormat = new ChoiceFormat(limits, formats);

        Assert.assertEquals("以数字为键找值：",
                "周一", numberFormat.format(1));
        Assert.assertEquals("以数字为键找值：",
                "周四", numberFormat.format(4.3));
        Assert.assertEquals("以数字为键找值：",
                "周五", numberFormat.format(5.8));
        Assert.assertEquals("以数字为键找值：",
                "周日", numberFormat.format(9.1));
        Assert.assertEquals("以数字为键找值：",
                "周日", numberFormat.format(11));
    }

}
